﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DevFx.Biz
{
    public class PagedList<T> : List<T>
    {
        public PagedList(IQueryable<T> source, int totalRecords, int index, int pageSize)
        {
            TotalCount = totalRecords;
            TotalPages = TotalCount / pageSize;

            if (TotalCount % pageSize > 0)
                TotalPages++;

            PageSize = pageSize;
            PageIndex = index;
            AddRange(source.ToList());
        }

        public PagedList(IEnumerable<T> source, int totalRecords, int index, int pageSize)
        {
            TotalCount = totalRecords;
            TotalPages = totalRecords / pageSize;

            if (totalRecords % pageSize > 0)
                TotalPages++;

            PageSize = pageSize;
            PageIndex = index;
            AddRange(source.ToList());
        }

        #region IPagedList Members

        public int TotalPages { get; set; }

        public int TotalCount { get; set; }

        public int PageIndex { get; set; }

        public int PageSize { get; set; }

        public bool IsPreviousPage
        {
            get { return (PageIndex > 0); }
        }

        public bool IsNextPage
        {
            get { return ((PageIndex + 1) * PageSize) <= TotalCount; }
        }

        #endregion
    }
}
